#include <algorithm/analytical_model/io/json/converter/analytical_model/SimulationPara.h>
#include <algorithm/analytical_model/io/json/converter/shared/utils/Vec2.h>

using namespace solar;

void solar::tag_invoke(const boost::json::value_from_tag& /*unused*/,
                       boost::json::value& json_value, const SimulationPara& simulation_para)
{
    auto receiver_pixel_size =
        SOLAR_GET_VALUE(SimulationPara, receiver_pixel_size_, simulation_para);
    auto micro_heliostat_pixel_size =
        SOLAR_GET_VALUE(SimulationPara, micro_heliostat_pixel_size_, simulation_para);
    json_value = {
        {       "receiver_pixel_size",        boost::json::value_from(receiver_pixel_size)},
        {"micro_heliostat_pixel_size", boost::json::value_from(micro_heliostat_pixel_size)}
    };
}

auto solar::tag_invoke(const boost::json::value_to_tag<SimulationPara>& /*unused*/,
                       const boost::json::value& json_value) -> SimulationPara
{
    const auto* value_ptr = json_value.if_object();
    if (value_ptr == nullptr)
    {
        return {};
    }
    SimulationPara result;
    if (const auto* receiver_pixel_size_value = value_ptr->if_contains("receiver_pixel_size");
        receiver_pixel_size_value != nullptr)
    {
        SOLAR_SET_VALUE(SimulationPara, receiver_pixel_size_,
                        boost::json::value_to<Vec2>(*receiver_pixel_size_value), result)
    }
    if (const auto* micro_heliostat_pixel_size_value =
            value_ptr->if_contains("micro_heliostat_pixel_size");
        micro_heliostat_pixel_size_value != nullptr)
    {
        SOLAR_SET_VALUE(SimulationPara, micro_heliostat_pixel_size_,
                        boost::json::value_to<Vec2>(*micro_heliostat_pixel_size_value), result)
    }
    return result;
}
